package com.yzz.composeweatherproject.activity

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.graphics.Color
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import com.yzz.composeweatherproject.activity.ui.theme.ComposeWeatherProjectTheme

abstract class BaseActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            ComposeWeatherProjectTheme {
                setUiControlTool()
                initView()
            }

        }
    }

    @Composable
    abstract fun initView()
}

/**
 * 设置状态栏和导航栏的颜色
 */
@Composable
private fun setUiControlTool() {
    // 记住一个 SystemUiController
    val systemUiController = rememberSystemUiController()
    val useDarkIcons = MaterialTheme.colors.isLight
    SideEffect {
        // 将所有系统栏颜色更新为透明，如果我们处于浅色主题，则使用深色图标
        systemUiController.setSystemBarsColor(
            if (useDarkIcons) {
                Color.White
            } else {
                Color.Black
            },
            darkIcons = useDarkIcons
        )
        //如果想单独设置就分别调用 setStatusBarsColor() 和 setNavigationBarColor()
    }
}
